package com.zhihuichongcheng.application.ui.cricle.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.smartlib.cmnObject.recycleView.OnItemOnclick;
import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.bean.cricle.CricleTypeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 3water on 2016/11/8.
 */

public class CircleTitleTypeAdapter extends RecyclerView.Adapter<CircleTitleTypeAdapter.ViewHold> {
    private List<CricleTypeBean> mListData = new ArrayList<>();
    private Context mContext;
    private int index;
    private OnItemOnclick<CricleTypeBean> onItemOnclick;

    public CircleTitleTypeAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listadapter_cricle_title_type, null);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, final int position) {
        final CricleTypeBean bean = mListData.get(position);
        holder.mTvTitle.setText(bean.getCategoryName());
        if (index == position) {
            holder.mTvTitle.setTextColor(mContext.getResources().getColor(R.color.color_278ae3));
            holder.viewBottom.setVisibility(View.VISIBLE);
        } else {
            holder.viewBottom.setVisibility(View.INVISIBLE);
            holder.mTvTitle.setTextColor(mContext.getResources().getColor(R.color.color_999));
        }
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemOnclick != null) {
                    onItemOnclick.onClick(bean, position);
                }
            }
        });
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    public void setOnItemOnclick(OnItemOnclick<CricleTypeBean> onItemOnclick) {
        this.onItemOnclick = onItemOnclick;
    }

    public void setData(List<CricleTypeBean> list) {
        this.mListData = list;
    }

    class ViewHold extends RecyclerView.ViewHolder {
        private TextView mTvTitle;
        private View viewBottom, view;

        public ViewHold(View itemView) {
            super(itemView);
            view = itemView;
            mTvTitle = (TextView) itemView.findViewById(R.id.tv_title);
            viewBottom = (View) itemView.findViewById(R.id.view_bottom);
        }
    }
}
